#!/usr/bin/env python
# -*- mode: python; coding: utf-8; -*-
##--------------------------------------------------------------------------##
##
## Copyright (C) 1998-2003 Markus Oberhumer <markus@oberhumer.com>
## Copyright (C) 2003 Mt. Hood Playing Card Co.
## Copyright (C) 2005-2010 Skomoroh <skomoroh@users.sourceforge.net>
## Copyright (C) 2010-2013 Jeremy Austin-Bardo <tjaustinbardo@gmail.com>
##
## This program is free software: you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published by
## the Free Software Foundation, version 3 of the License.
##
## This program is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
## GNU General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with this program.  If not, see <http://www.gnu.org/licenses/>.
##
##--------------------------------------------------------------------------##
from .info import GT, SL, GC

GAMES_BY_TYPE = (
    (n_('Baker\'s Dozen type'),
        lambda gi, gt=GT.BAKERS_DOZEN:
            gi['si']['game_type'] == gt),
    (n_('Beleaguered Castle type'),
        lambda gi, gt=GT.BELEAGUERED_CASTLE:
            gi['si']['game_type'] == gt),
    (n_('Canfield type'),
         lambda gi, gt=GT.CANFIELD:
            gi['si']['game_type'] == gt),
    (n_('Fan type'),
        lambda gi, gt=GT.FAN_TYPE:
            gi['si']['game_type'] == gt),
    (n_('Forty Thieves type'),
        lambda gi, gt=GT.FORTY_THIEVES:
            gi['si']['game_type'] == gt),
    (n_('FreeCell type'),
        lambda gi, gt=GT.FREECELL:
            gi['si']['game_type'] == gt),
    (n_('Golf type'),
        lambda gi, gt=GT.GOLF:
            gi['si']['game_type'] == gt),
    (n_('Gypsy type'),
        lambda gi, gt=GT.GYPSY:
            gi['si']['game_type'] == gt),
    (n_('Klondike type'),
         lambda gi, gt=GT.KLONDIKE:
            gi['si']['game_type'] == gt),
    (n_('Montana type'),
        lambda gi, gt=GT.MONTANA:
            gi['si']['game_type'] == gt),
    (n_('Napoleon type'),
        lambda gi, gt=GT.NAPOLEON:
            gi['si']['game_type'] == gt),
    (n_('Numerica type'),
        lambda gi, gt=GT.NUMERICA:
            gi['si']['game_type'] == gt),
    (n_('Pairing type'),
        lambda gi, gt=GT.PAIRING:
            gi['si']['game_type'] == gt),
    (n_('Raglan type'),
        lambda gi, gt=GT.RAGLAN:
            gi['si']['game_type'] == gt),
    (n_('Simple games'),
        lambda gi, gt=GT.SIMPLE_TYPE:
            gi['si']['game_type'] == gt),
    (n_('Spider type'),
        lambda gi, gt=GT.SPIDER:
            gi['si']['game_type'] == gt),
    (n_('Terrace type'),
        lambda gi, gt=GT.TERRACE:
            gi['si']['game_type'] == gt),
    (n_('Yukon type'),
        lambda gi, gt=GT.YUKON:
            gi['si']['game_type'] == gt),
    (n_('One-Deck games'),
        lambda gi, gt=GT.ONE_DECK:
            gi['si']['game_type'] == gt),
    (n_('Two-Deck games'),
        lambda gi, gt=GT.TWO_DECK:
            gi['si']['game_type'] == gt),
    (n_('Three-Deck games'),
        lambda gi, gt=GT.THREE_DECK:
            gi['si']['game_type'] == gt),
    (n_('Four-Deck games'),
        lambda gi, gt=GT.FOUR_DECK:
            gi['si']['game_type'] == gt),
)

SELECT_ORIGINAL_GAME_BY_TYPE = (
    (n_('French type'),
        lambda gi, gf=GT.ORIGINAL, gc=GC.FRENCH:
            gi['si']['game_flags'] & gf and gi['category'] == gc),
    (n_('Ganjifa type'),
        lambda gi, gf=GT.ORIGINAL, gt=(GT.MUGHAL_GANJIFA,
                          GT.NAVAGRAHA_GANJIFA, GT.DASHAVATARA_GANJIFA,):
            gi['si']['game_flags'] & gf and gi['si']['game_type'] in gt),
    (n_('Hanafuda type'),
        lambda gi, gf=GT.ORIGINAL, gt=GT.HANAFUDA:
            gi['si']['game_flags'] & gf and gi['si']['game_type'] == gt),
    (n_('Hex A Deck type'),
        lambda gi, gf=GT.ORIGINAL, gt=GT.HEXADECK:
            gi['si']['game_flags'] & gf and gi['si']['game_type'] == gt),
    (n_('Tarock type'),
        lambda gi, gf=GT.ORIGINAL, gt=GT.TAROCK:
            gi['si']['game_flags'] & gf and gi['si']['game_type'] == gt),
)

GAMES_SUBMIT_BY_TYPE = (
    (n_('French type'),
        lambda gi, gf=GT.CONTRIB, gc=GC.FRENCH:
            gi['si']['game_flags'] & gf and gi['category'] == gc),
    (n_('Ganjifa type'),
        lambda gi, gf=GT.CONTRIB, gt=(GT.MUGHAL_GANJIFA,
                          GT.NAVAGRAHA_GANJIFA, GT.DASHAVATARA_GANJIFA,):
            gi['si']['game_flags'] & gf and gi['si']['game_type'] in gt),
    (n_('Hanafuda type'),
        lambda gi, gf=GT.CONTRIB, gt=GT.HANAFUDA:
            gi['si']['game_flags'] & gf and gi['si']['game_type'] == gt),
    (n_('Hex A Deck type'),
        lambda gi, gf=GT.CONTRIB, gt=GT.HEXADECK:
            gi['si']['game_flags'] & gf and gi['si']['game_type'] == gt),
    (n_('Tarock type'),
        lambda gi, gf=GT.CONTRIB, gt=GT.TAROCK:
            gi['si']['game_flags'] & gf and gi['si']['game_type'] == gt),
)

GAMES_ORIENT_BY_TYPE = (
    (n_('Dashavatara Ganjifa type'),
         lambda gi, gt=GT.DASHAVATARA_GANJIFA:
            gi['si']['game_type'] == gt),
    (n_('Ganjifa type'),
         lambda gi, gt=(GT.MUGHAL_GANJIFA, GT.NAVAGRAHA_GANJIFA,
                        GT.DASHAVATARA_GANJIFA,):
             gi['si']['game_type'] in gt),
    (n_('Hanafuda type'),
        lambda gi, gt=GT.HANAFUDA:
            gi['si']['game_type'] == gt),
    (n_('Mughal Ganjifa type'),
        lambda gi, gt=GT.MUGHAL_GANJIFA:
            gi['si']['game_type'] == gt),
    (n_('Navagraha Ganjifa type'),
         lambda gi, gt=GT.NAVAGRAHA_GANJIFA:
            gi['si']['game_type'] == gt),
)

GAMES_OTHERS_BY_TYPE = (
    (n_('Shisen-Sho'),
        lambda gi, gt=GT.SHISEN_SHO: gi['si']['game_type'] == gt),
    (n_('Hex A Deck type'),
        lambda gi, gt=GT.HEXADECK: gi['si']['game_type'] == gt),
    (n_('Matrix type'),
        lambda gi, gt=GT.MATRIX: gi['si']['game_type'] == gt),
    (n_('Memory type'),
        lambda gi, gt=GT.MEMORY: gi['si']['game_type'] == gt),
    (n_('Poker type'),
        lambda gi, gt=GT.POKER_TYPE: gi['si']['game_type'] == gt),
    (n_('Puzzle type'),
        lambda gi, gt=GT.PUZZLE_TYPE: gi['si']['game_type'] == gt),
    (n_('Tarock type'),
        lambda gi, gt=GT.TAROCK: gi['si']['game_type'] == gt),
)

GAMES_BY_SKILL = (
    (n_('Luck only'),
        lambda gi, sl=SL.LUCK: gi['skill_level'] == sl),
    (n_('Mostly luck'),
        lambda gi, sl=SL.MOSTLY_LUCK: gi['skill_level'] == sl),
    (n_('Balanced'),
        lambda gi, sl=SL.BALANCED: gi['skill_level'] == sl),
    (n_('Mostly skill'),
        lambda gi, sl=SL.MOSTLY_SKILL: gi['skill_level'] == sl),
    (n_('Skill only'),
        lambda gi, sl=SL.SKILL: gi['skill_level'] == sl),
)

GAMES_BY_SIMILAR = (
    # Atari ST Patience game v2.13 (we have 10 out of 10 games)
    ('Atari ST Patience', lambda gi, gf=GT.ATARI: gi['si']['game_flags'] & gf),
    # Gnome AisleRiot 2.2.0 (we have 61 out of 70 games)
    #  still missing: Gay gordons, Helsinki, Isabel, Labyrinth, Quatorze,
    #    Thieves, Treize, Valentine, Yeld.
    ('Gnome AisleRiot', lambda gi, gf=GT.GNOME: gi['si']['game_flags'] & gf),
    # KDE Patience 2.0 from KDE 3.1.1 (we have 15 out of 15 games)
    ('KDE Patience', lambda gi, gf=GT.KDE: gi['si']['game_flags'] & gf),
    # xpat2 1.06 (we have 14 out of 16 games)
    #   still missing: Michael's Fantasy, modCanfield
    ('xpat2', lambda gi, gf=GT.XPAT: gi['si']['game_flags'] & gf),
)

GAMES_BY_INVENTORS = (
    ('Paul Alfille', lambda gi: 'Paul Alfille' in gi['si']['credit']),
    ('C.L. Baker',  lambda gi: 'C.L. Baker' in gi['si']['credit']),
    ('David Bernazzani', lambda gi: 'David Bernazzani' in gi['si']['credit']),
    ('Gordon Bower', lambda gi: 'Gordon Bower' in gi['si']['credit']),
    ('Art Cabral', lambda gi: 'Art Cabral' in gi['si']['credit']),
    ('Robert Harbin', lambda gi: 'Robert Harbin' in gi['si']['credit']),
    ('Robert Hogue', lambda gi: 'Robert Hogue' in gi['si']['credit']),
    ('Charles Jewell', lambda gi: 'Charles Jewell' in gi['si']['credit']),
    ('Michael Keller', lambda gi: 'Michael Keller' in gi['si']['credit']),
    ('Fred Lunde', lambda gi: 'Fred Lunde' in gi['si']['credit']),
    ('Albert Morehead', lambda gi: 'Albert Morehead' in gi['si']['credit']),
    ('Geoffrey Mott-Smith', lambda gi: 'Geoffrey Mott-Smith' in gi['si']['credit']),
    ('David Parlett', lambda gi: 'David Parlett' in gi['si']['credit']),
    ('Randy Rasa', lambda gi: 'Randy Rasa' in gi['si']['credit']),
    ('Captain Jeffrey T. Spaulding', lambda gi: 'Captain Jeffrey T. Spaulding' in gi['si']['credit']),
    ('Adam Selene', lambda gi: 'Adam Selene' in gi['si']['credit']),
    ('John Stoneham', lambda gi: 'John Stoneham' in gi['si']['credit']),
    ('Bryan Stout', lambda gi: 'Bryan Stout' in gi['si']['credit']),
    ('Bill Taylor', lambda gi: 'Bill Taylor' in gi['si']['credit']),
    ('Thomas Warfield', lambda gi: 'Thomas Warfield' in gi['si']['credit']),
    )

GAMES_BY_VERSION = (
    ('New games in v.1.00', lambda gi: gi['si']['version'] == '1.00'),
    ('New games in v.1.01', lambda gi: gi['si']['version'] == '1.01'),
    ('New games in v.1.02', lambda gi: gi['si']['version'] == '1.02'),
    ('New games in v.1.03', lambda gi: gi['si']['version'] == '1.03'),
    ('New games in v.1.10', lambda gi: gi['si']['version'] == '1.10'),
    ('New games in v.1.11', lambda gi: gi['si']['version'] == '1.11'),
    ('New games in v.2.00', lambda gi: gi['si']['version'] == '2.00'),
    ('New games in v.2.01', lambda gi: gi['si']['version'] == '2.01'),
    ('New games in v.2.02', lambda gi: gi['si']['version'] == '2.02'),
    ('New games in v.2.90', lambda gi: gi['si']['version'] == '2.90'),
    ('New games in v.2.99', lambda gi: gi['si']['version'] == '2.99'),
    ('New games in v.3.00', lambda gi: gi['si']['version'] == '3.00'),
    ('New games in v.3.10', lambda gi: gi['si']['version'] == '3.10'),
    ('New games in v.3.20', lambda gi: gi['si']['version'] == '3.20'),
    ('New games in v.3.21', lambda gi: gi['si']['version'] == '3.21'),
    ('New games in v.3.30', lambda gi: gi['si']['version'] == '3.30'),
    ('New games in v.3.40', lambda gi: gi['si']['version'] == '3.40'),
    ('New games in v.4.00', lambda gi: gi['si']['version'] == '4.00'),
    ('New games in v.4.20', lambda gi: gi['si']['version'] == '4.20'),
    ('New games in v.4.30', lambda gi: gi['si']['version'] == '4.30'),
    ('New games in v.4.41', lambda gi: gi['si']['version'] == '4.41'),
    ('New games in v.4.60', lambda gi: gi['si']['version'] == '4.60'),
    ('New games in v.4.70', lambda gi: gi['si']['version'] == '4.70'),
    ('New games in v.fc-0.5.0', lambda gi: gi['si']['version'] == '0.50fc'),
    ('New games in v.fc-0.8.0', lambda gi: gi['si']['version'] == '0.80fc'),
    ('New games in v.fc-0.9.0', lambda gi: gi['si']['version'] == '0.90fc'),
    ('New games in v.fc-0.9.1', lambda gi: gi['si']['version'] == '0.91fc'),
    ('New games in v.fc-0.9.2', lambda gi: gi['si']['version'] == '0.92fc'),
    ('New games in v.fc-0.9.3', lambda gi: gi['si']['version'] == '0.93fc'),
    ('New games in v.fc-0.9.4', lambda gi: gi['si']['version'] == '0.940fc'),
    ('New games in v.fc-1.0', lambda gi: gi['si']['version'] == '1.00fc'),
    ('New games in v.fc-1.1', lambda gi: gi['si']['version'] == '1.10fc'),
    ('New games in v.fc-2.0', lambda gi: gi['si']['version'] == '2.00fc'),
    )

GAMES_BY_NCARDS = (
    (_('32 cards'),
        lambda gi: gi['si']['ncards'] == 32),
    (_('48 cards'),
        lambda gi: gi['si']['ncards'] == 48),
    (_('52 cards'),
        lambda gi: gi['si']['ncards'] == 52),
    (_('64 cards'),
        lambda gi: gi['si']['ncards'] == 64),
    (_('78 cards'),
        lambda gi: gi['si']['ncards'] == 78),
    (_('104 cards'),
        lambda gi: gi['si']['ncards'] == 104),
    (_('144 cards'),
        lambda gi: gi['si']['ncards'] == 144),
    (_('Other number'),
        lambda gi: gi['si']['ncards'] not in (32, 48, 52, 64, 78, 104, 144)),
    )

GAMES_BY_NDECKS = (
    (_('1 deck games'),
        lambda gi: gi['si']['decks'] == 1),
    (_('2 deck games'),
        lambda gi: gi['si']['decks'] == 2),
    (_('3 deck games'),
        lambda gi: gi['si']['decks'] == 3),
    (_('4 deck games'),
        lambda gi: gi['si']['decks'] == 4),
    )

GAMES_BY_NDEALS = (
    (_('No redeal'),
        lambda gi: gi['si']['redeals'] == 0),
    (_('1 redeal'),
        lambda gi: gi['si']['redeals'] == 1),
    (_('2 redeals'),
        lambda gi: gi['si']['redeals'] == 2),
    (_('3 redeals'),
        lambda gi: gi['si']['redeals'] == 3),
    (_('Unlimited redeals'),
        lambda gi: gi['si']['redeals'] == -1),
#        (_('Variable redeals'),
#            lambda gi: gi['si']['redeals'] == -2),
    (_('Other number of redeals'),
        lambda gi: gi['si']['redeals'] not in (-1, 0, 1, 2, 3)),
    )

GAME_BY_GROUPS = (
    (_('Games for Children (very easy)'),
        lambda gi: gi['si']['game_flags'] & GT.CHILDREN),
    (_('Games with Scoring'),
        lambda gi: gi['si']['game_flags'] & GT.SCORE),
    (_('Games with Separate Decks'),
        lambda gi: gi['si']['game_flags'] & GT.SEPARATE_DECKS),
    (_('Open Games (all cards visible)'),
        lambda gi: gi['si']['game_flags'] & GT.OPEN),
    (_('Relaxed Variants'),
        lambda gi: gi['si']['game_flags'] & GT.RELAXED),
    )